package chapter1.fundamentals.exercise;

/**
 * @author quanlinlin on 2018/10/25 20:17.
 * @version 1.0
 */
public class E_9 {

    public static void main(String[] args) {
        System.out.println(integerToBinary(21));

        System.out.println(Integer.toBinaryString(21));
    }

    public static String integerToBinary(int num) {
        String result = "";

        while (num > 1) {
            result = num % 2 + result;
            num = num / 2;
        }
        return num + result;
    }

    public static String anwser(int N) {
        String s = "";
        for (int n = N; n > 0; n /= 2) {
            s = n % 2 + s;
        }
        return s;
    }
}
